﻿<UserControl x:Class="FormValidationExample.View.InterestSelectorView"
			 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
			 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
			 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
			 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:ViewModel="clr-namespace:FormValidationExample.ViewModel"
             mc:Ignorable="d"
			 d:DataContext="{d:DesignInstance ViewModel:InterestSelectorViewModel}"
			 x:Name="root">

	<UserControl.Resources>
		<DataTemplate x:Key="InterestItemTemplate">
			<Grid d:DataContext="{d:DesignInstance ViewModel:InterestItemViewModel}"
				  Margin="0,0,0,5">
				<CheckBox Content="{Binding Name}"
						  IsChecked="{Binding IsSelected, Mode=TwoWay}" />
			</Grid>
		</DataTemplate>
	</UserControl.Resources>	
	
	<Validation.ErrorTemplate>
		<ControlTemplate>
			<Grid>			

				<AdornedElementPlaceholder Name="customAdorner"
										   VerticalAlignment="Center">
				</AdornedElementPlaceholder>				
				
				<TextBlock x:Name="textBlock"
						   Text="{Binding ElementName=customAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"
						   HorizontalAlignment="Right"
						   Margin="10,0,5,0"
						   MaxWidth="150"
						   TextWrapping="Wrap"
						   TextTrimming="WordEllipsis"
						   Foreground="Red" />
			</Grid>
		</ControlTemplate>
	</Validation.ErrorTemplate>
	
	<Grid>
		<ItemsControl ItemsSource="{Binding Interests}"
					  ItemTemplate="{StaticResource InterestItemTemplate}" />
	</Grid>
</UserControl>
